#include "descr/descr_character_parser.h"


using namespace std;


bool DescrCharacterParser::parse(std::string line)
{
	string token = popNextToken(line);

	if (token.compare("type") == 0)
	{
		parsingCharacterType.reset(new Character::Type);
		parsingCharacterType->name = popNextToken(line, COMMA);
		
		Character::Type::add(parsingCharacterType);
	}
	else if (token.compare("wage_base") == 0)
	{
		istringstream buffer(popNextToken(line));
		buffer >> parsingCharacterType->wageBase;
	}
	else if (token.compare("starting_action_points") == 0)
	{
		istringstream buffer(popNextToken(line));

		if (parsingCharacterType.get() == 0)
		{
			buffer >> Character::Type::defaultStartingActionPoints;
		}
		else
		{
			buffer >> parsingCharacterType->startingActionPoints;
		}
	}
	else if (token.compare("faction") == 0)
	{
		parsingFactionID = popNextToken(line);
	}
	else if (token.compare("strat_model") == 0)
	{
		string casFileName = popNextToken(line);

		parsingCharacterType->addStratModelID(parsingFactionID, casFileName);
	}

	return true;
}